package com.driver.core;

import com.driver.core.convert.SqlServerService;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;


/**
 * 作者 :熊荣健
 * 时间: 2019.8
 * 备注: 里面的代码都是自己敲出来的。自动生成mapper等
 */
public class DBManager {
    private static Configuraction config;

    public static Configuraction getConfig() {
        return config;
    }

    public static void setConfig(Configuraction config) {
        DBManager.config = config;
    }


    public static Connection getConn() {
        try {
            Class.forName(config.getDriver());
            return DriverManager.getConnection(config.getUrl(), config.getUsername(), config.getPassword());
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static void createFile() {
        List<Table> tables = null;
        try {
            tables = TableManager.getTable();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        for (Table table : tables) {
            FileManager.createFile(table);
        }

    }

    public static void main(String[] args) throws SQLException {
        sqlserver();

//        mysql();
    }

    private static void sqlserver() {
        Configuraction config = new Configuraction();
        config.setUrl("jdbc:sqlserver://192.168.35.23:1433;databaseName=weChatTest");
        config.setUsername("lllogin");
        config.setPassword("rw1894tla");
        config.setTable("wx_t_fansmsg");
        config.setPackagePreffix("com.lilanz.microservice.svrsaletool.wechat");
        config.setDeleteTableNamePreffix("wx_t_");
        config.setLombok(true);
        DBManager.setConfig(config);
        createFile();

    }
//    private static void sqlserver() {
//        Configuraction config = new Configuraction();
//        config.setUrl("jdbc:sqlserver://127.0.0.1;DatabaseName=weChatTest");
//        config.setUsername("sa");
//        config.setPassword("A5631156a");
//        config.setTable("ys_t_FacePass_Log");
//        config.setPackagePreffix("com.lilanz.microservice.svrsaletool.wechat");
//        config.setDeleteTableNamePreffix("ys_t_FacePass_");
//        config.setLombok(true);
//        DBManager.setConfig(config);
//        createFile();
//        Set<String> set = SqlServerService.set;
//        for (String s : set) {
//            System.out.println(s);
//        }
//    }

    private static void mysql() {
        Configuraction config = new Configuraction();
        config.setUrl("jdbc:mysql://192.168.35.125:3306/game");
        config.setUsername("root");
        config.setPassword("Newrw1894tla=");
        config.setTable("user_info");
        config.setPackagePreffix("com.lilanz.game");
//        config.setDeleteTableNamePreffix("shop_");
        config.setLombok(true);
        DBManager.setConfig(config);
        createFile();


    }


}
